<%
# We have to remove search form params before the url_for method call, otherwise it throughs it on
search_params = params[:search]
params.merge!(:search => nil)
href = url_for(params_for(:action => :update_table, :escape => false).delete_if{|k,v| k == 'search'})
-%>
<%= form_remote_tag :url => href,
                    :method => :get,
                    :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')",
                    :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{search_form_id}');",
                    :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');",
                    :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')",
                    :update => active_scaffold_content_id,
                    :html => { :href => href, :id => search_form_id, :class => 'search' } %>

  <ol class="form">
    <% active_scaffold_config.field_search.columns.each do |column| -%>
      <li class="form-element">
        <dl>
          <dt>
            <label for="<%= "search_#{column.name}" %>"><%= column.label %></label>
          </dt>
        <dd>
          <% if column.options[:field_search] == :range
                #FIXME 2007-11-10 (EJM) Level=0 - For now :help_string => "", to make turn off TextFieldWithExample which is not happy with these range fields on the search form. The hidden field being the same name as the input is messing things up.
                value = nil
                value = search_params[column.name][:range_from] if search_params and search_params[column.name]
                options = {:name => "search[#{column.name}][range_from]", :id => "search_#{column.name}_range_from", :help_string => "", :class => "range-input"}
                html = active_scaffold_input_for_search(column, options)
                html << content_tag("span", as_(" to "), {:class => "description"})
                value = nil
                value = search_params[column.name][:range_to] if search_params and search_params[column.name]
                options[:name] = "search[#{column.name}][range_to]"
                options[:id] = "search_#{column.name}_range_to"
                html << active_scaffold_input_for_search(column, options)
              else
                #FIXME 2007-11-10 (EJM) Level=0 - For now :help_string => "", to make turn off TextFieldWithExample which is not happy with these range fields on the search form. The hidden field being the same name as the input is messing things up.
                html = active_scaffold_input_for_search(column, {:blank_if_nil => true, :help_string => ""})
              end
        %>
        <%= html -%>
        </dd>
      </dl>
    </li>
    <% end -%>
  </ol>
  <p class="form-footer">
    <%= submit_tag as_('Search'), :class => "submit" %>
    <!-- <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_('Reset') -%></a> -->
    <% href = url_for(params_for(:action => :reset_search, :escape => false)) %>
    <%= link_to_remote as_('Reset'), {:url => href,
                              :method => :get,
                              :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')",
                              :update => active_scaffold_content_id}, {:class => "cancel"} %>
    <%= loading_indicator_tag(:action => :search) %>
  </p>
</form>

<script type="text/javascript">
//<![CDATA[
  Form.focusFirstElement('<%= search_form_id -%>');
//]]>
</script>
